package com.jxnu.controller;

import com.jxnu.domain.Category;
import com.jxnu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping(value="inter")
public class InterController {
    @Autowired
    UserService service;

    @RequestMapping(value = "test1")
    public  String test1(){
        System.out.println("test is running.......");
        return "success";
    }

    @RequestMapping(value = "test2")
    public  String test2(String username,String password){
       if("tom".equals(username) && "123456".equals(password)){
           return "success";
       }else {
           return "error";
       }
    }

    @RequestMapping(value = "test3")
    public  String test3(String username, String password, HttpSession session){
        int i = 1 / 0;
        if("tom".equals(username) && "123456".equals(password)){
            session.setAttribute("user",true);
            return "success";
        }else {
            return "error";
        }
    }

    @RequestMapping(value = "test4")
    public  String test4(Model model){
        List<Category> list = service.findAll();
        model.addAttribute("list",list);
        return "list";
    }
}
